package com.hp.ppm.ext.service;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.config.PropertiesConfig;
import com.config.PropertiesService;

@WebServlet(urlPatterns = "/gosys")
public class GOSysService extends HttpServlet {

	PropertiesConfig config = PropertiesService.getApplicationConfig();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String username=req.getParameter("mname");
		 resp.setCharacterEncoding("UTF-8");  
		 resp.setContentType("application/json; charset=utf-8"); 
		if(username==null||username.length()<2){
			resp.getOutputStream().print("user name is error");
		}else{
			 String sanme=username.substring( 0,username.length()-1 );
			 resp.getOutputStream().write((config.getProperty("go.sys")+"mname="+sanme+"&mpwd="+UserCache.getInstancei().get(sanme)).getBytes());
		}
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	

}
